Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve redirect error message #460

Merged
merged 5 commits into from
Jun 8, 2019
Merged

Conversation

bhrutledge
Copy link
Contributor

Closes #310

  • Adds a suggested course of action to the RedirectDetected error message in upload
  • Moves error message to exception class
  • Updates register to use the new message (with a test)
  • Adds conftest.py for reused fixtures

The original issue has a suggestion to avoid the redirect as a special case for PyPI. I would probably do that in utils.normalize_repository_url by appending a trailing slash if the URL is in _HOSTNAMES. However, it seemed like a more useful error message would benefit other repositories, and might be sufficient for the official ones.

@codecov
Copy link

codecov bot commented May 12, 2019

Codecov Report

Merging #460 into master will increase coverage by 2.18%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #460      +/-   ##
==========================================
+ Coverage   80.74%   82.93%   +2.18%     
==========================================
  Files          14       14              
  Lines         748      750       +2     
  Branches      108      108              
==========================================
+ Hits          604      622      +18     
+ Misses        110       92      -18     
- Partials       34       36       +2
Impacted Files Coverage Δ
twine/commands/register.py 58.33% <100%> (+58.33%) ⬆️
twine/commands/upload.py 91.66% <100%> (+4.16%) ⬆️
twine/exceptions.py 100% <100%> (ø) ⬆️
twine/wininst.py 31.57% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da07f78...09aa4e2. Read the comment docs.

@classmethod
def from_args(cls, repository_url, redirect_url):
msg = "\n".join([
"Unexpected redirect from {0} to {1}."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we support 2.6 any longer meaning you can drop the numbers here, if you'd like.

msg = "\n".join([
"Unexpected redirect from {0} to {1}."
.format(repository_url, redirect_url),
"You might need to change the configured repository URL.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the more common cases a redirect here is innocuous and perhaps changing the URL is fine. But there could be cases where folks are being redirected to a malicious URL that will be able to:

  • steal credentials
  • store the uploaded package data

In that case, I don't want folks to think "Geeze, really?! I have to copy and paste this into my pypirc for this stupid tool to work?! WTF IS WRONG WITH THOSE PEOPLE" and then to angrily and carelessly copy and paste the malicious URL.

Granted, I think the this is very unlikely, but still I would like to see more cautious wording. Something like:

You should examine the URLs carefully and if you trust them, update your configured repository URL.

Also, would you share your reasoning for using a newline to separate these lines? Has the project moved towards preferring newlines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I wordsmithed the error message a bit in 1b80776. Re: newlines, I thought it was more readable, and there are a couple instances of them being used in the project. But I don't feel strongly, and am happy to change it.

@classmethod
def from_args(cls, target_url, default_url, test_url):
"""Return an UploadToDeprecatedPyPIDetected instance."""
return cls("You're trying to upload to the legacy PyPI site '{}'. "
"Uploading to those sites is deprecated. \n "
"The new sites are pypi.org and test.pypi.org. Try using "
"{} (or {}) to upload your packages instead. "
"These are the default URLs for Twine now. \n More at "
"https://packaging.python.org/guides/migrating-to-pypi-org/"
" .".format(target_url, default_url, test_url)
)

twine/twine/utils.py

Lines 122 to 132 in da07f78

except KeyError:
msg = (
"Missing '{repo}' section from the configuration file\n"
"or not a complete URL in --repository-url.\n"
"Maybe you have a out-dated '{cfg}' format?\n"
"more info: "
"https://docs.python.org/distutils/packageindex.html#pypirc\n"
).format(
repo=repository,
cfg=config_file
)

@bhrutledge
Copy link
Contributor Author

@sigmavirus24 Is there more that I can/should do with this pull request?

Copy link
Member

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay @bhrutledge I'm not really spending time on F/OSS and it was purely chance that I noticed this in my email today. It may be best to work with another maintainer on this going forward.

upload.upload(upload_settings, [WHEEL_FIXTURE])

assert err.value.args[0] == (
"https://test.pypi.org/legacy attempted to redirect"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I struggle with often. As a CLI, our user interface is what we print out. With that in mind, tests like these quickly become frustrating and feel overly strict when updating messages/message formatting/etc. I think testing that we're showing the correct data is important, but I also don't want us to test that we always show this message. I can imagine a future where we use internationalization to improve the experience and someone contributing from a locale that isn't en_* sees a test failure here too.

What do you think are the important parts of this message? What should we test for and what can we eliminate from this assertion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @sigmavirus24. In this case, I followed the pattern of the existing tests, but in generally I agree with your opinion. To that end, in f326758 I modified the assertions to check for what I think are the important bits, like URLs.

@bhrutledge
Copy link
Contributor Author

@theacodes or @di: in light of this comment from @sigmavirus24, and as the other maintainers that I've interacted with, any thoughts on this PR?

I'm not really spending time on F/OSS and it was purely chance that I noticed this in my email today. It may be best to work with another maintainer on this going forward.

@di
Copy link
Member

di commented Jun 3, 2019

Just a heads up, I'm not technically a twine maintainer, but @theacodes or @jaraco are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

leaving out a trailing slash in the pypi URL causes twine to fail with a 410
4 participants